package com.cloudcc.mobile.im.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.cloudcc.mobile.im.IMHelper;
import com.cloudcc.mobile.im.ui.VideoCallActivity;
import com.cloudcc.mobile.im.ui.VoiceCallActivity;
import com.easemob.util.EMLog;

/**
 * @Description: 语音通话跟视频通话的 接收器
 * @author wangzhiqiang
 * @date 2015-10-20 上午9:27:09
 * 
 */
public class CallReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		if (!IMHelper.getInstance().isLoggedIn())
			return;
		// 拨打方username
		String from = intent.getStringExtra("from");
		// call type
		String type = intent.getStringExtra("type");
		if ("video".equals(type)) { // 视频通话
			context.startActivity(new Intent(context, VideoCallActivity.class)
					.putExtra("username", from).putExtra("isComingCall", true)
					.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
		} else { // 音频通话
			context.startActivity(new Intent(context, VoiceCallActivity.class)
					.putExtra("username", from).putExtra("isComingCall", true)
					.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
		}
		EMLog.d("CallReceiver", "app received a incoming call");
	}

}
